
# -*- coding: utf8 -*-
#!/usr/bin/env python3

# win7 便签恢复小脚本
# 可以在 [%appdata%\Microsoft\Sticky Notes]这里找到StickyNotes.snt文件
__author__ = "fly"

import urllib.parse


def substrs(str, key):
    list = []
    idx = str.find(key)
    while idx > -1 :
        start_idx = idx
        idx = str.find(key, start_idx+1)
        sub = str[start_idx: idx]

        list.append(sub)
    return list


with open("StickyNotes.snt",'rb') as rf:
    file_data = rf.read()

    ascii_str = ascii(file_data)
    print('ascii_str: ' + str(type(ascii_str)))


    # find fs22
    fs22_list = substrs(ascii_str, 'fs22')

    # find \par\r\n
    pars_list = []
    for item in fs22_list:
        par_list = substrs(item, '\\par\\r\\n')
        pars_list.append(par_list)


    print()
    for item in pars_list:

        print('==============================================================================')
        for sub in item:
            sub = sub.replace('\\par', '')
            sub = sub.replace('\\r\\n', '')

            idx = sub.find('\\\'')
            sub = sub[idx:]
            if len(sub) == 1:
                continue

            sub = sub.replace("\\", '')
            sub = sub.replace('\'', '%')
            sub = urllib.parse.unquote(sub, encoding='gb2312', errors='replace')
            print(sub)

